package com.github.live.util.store;

import com.github.livebase.storage.LocalStorage;
import com.orhanobut.hawk.Hawk;

/**
 * @ClassName HawkStore
 * @description:
 * @author: biao532
 * @create: 2023-12-19 20:26
 * @Version 1.0
 **/
public class HawkStorage implements LocalStorage {
    private static LocalStorage store;
    public static LocalStorage getStore() {
        if (store == null) {
            synchronized (HawkStorage.class) {
                if (store == null) {
                    store = new HawkStorage();
                }
            }
        }
        return store;
    }

    private String prefix;
    public HawkStorage() {
        this.prefix = "HawkStore-";
    }
    public<T> T get(String key) {
        return Hawk.get(prefix + key);
    }

    public<T> T get(String key, T defaultValue) {
        return Hawk.get(prefix + key, defaultValue);
    }

    public<T> boolean put(String key, T value) {
        return Hawk.put(prefix + key, value);
    }

    @Override
    public <T> boolean put(String key, T value, long expire) {
        return Hawk.put(prefix+key, value);
    }

    public boolean delete(String key) {
        return Hawk.delete(prefix + key);
    }

    public boolean contains(String key) {
        return Hawk.contains(prefix + key);
    }

    @Override
    public boolean clear() {
        return Hawk.deleteAll();
    }


    public boolean isBuilt() {
        return Hawk.isBuilt();
    }

    public void destroy() {
        Hawk.destroy();
    }
}
